package com.study.service.api.print;

import com.google.common.collect.Maps;
import com.study.common.enums.PrintTypeEnum;
import com.study.common.util.PrintHelper;
import com.study.strategy.PrintTemplateStrategy;
import com.study.strategy.PrintTemplateStrategyFactory;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
import java.util.Map;

/**
 * 赣服通受理告知书
 * @author hw
 * @date 2022/11/2 14:28:17   
 */
@Lazy(value=false)
@Service
@RequiredArgsConstructor
public class SLGZSService implements PrintTemplateStrategy {

    private PrintTypeEnum printTypeEnum;

    @Autowired
    private DataSource dataSource;

    @Override
    public void afterPropertiesSet() throws Exception {
        PrintTemplateStrategyFactory.setHandler(PrintTypeEnum.SLGZS, this);
        this.printTypeEnum = PrintTypeEnum.SLGZS;
    }

    @Override
    public void printTemplate(String applyId, HttpServletRequest req, HttpServletResponse res) throws Exception{
        Map<String, Object> params = Maps.newHashMap();
        params.put("APPLY_ID", applyId);
        PrintHelper.printPdf(req, res, params, this.printTypeEnum.getFilePath(), dataSource.getConnection());
    }

}
